<template>
  <div>
<!--    用户管理-->
    <el-card v-if="index===1">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input
            placeholder="通过账号查找用户"
            clearable
            v-model="FindItem"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="FindUser"
            ></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" @click="Visible[0].dialogNewUserVisible=true">新增用户</el-button>
          <el-dialog title="新增用户" :visible.sync="Visible[0].dialogNewUserVisible">
            <el-form :model="AddUserForm" ref="form" :rules="rules">
              <el-form-item label="用户名" :label-width="formLabelWidth">
                <el-input v-model="AddUserForm.username" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="手机号" :label-width="formLabelWidth">
                <el-input v-model="AddUserForm.phone" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="账号" :label-width="formLabelWidth">
                <el-input v-model="AddUserForm.account" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="密码" :label-width="formLabelWidth">
                <el-input v-model="AddUserForm.password" autocomplete="off"></el-input>
              </el-form-item>

              <el-form-item label="性别" :label-width="formLabelWidth">
                <el-form-item>
                  <el-radio-group v-model="AddUserForm.sex">
                    <el-radio label="1">男</el-radio>
                    <el-radio label="2">女</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="Visible[0].dialogNewUserVisible = false">取 消</el-button>
              <el-button type="primary" @click="AddUsers">确 定</el-button>
            </div>
          </el-dialog>
        </el-col>
      </el-row>
      <el-dialog title="用户信息" :visible.sync="Visible[0].dialogTableVisible">
        <el-descriptions class="margin-top" title="用户信息" :column="1" size="medium" border>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-user"></i>
              用户名
            </template>
            {{ userInfo.userName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-mobile-phone"></i>
              手机号
            </template>
            {{ userInfo.phone }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-tickets"></i>
              账号
            </template>
            {{ userInfo.account }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i v-if="userInfo.gender==='女'" class="el-icon-female"></i>
              <i v-if="userInfo.gender==='男'"  class="el-icon-male"></i>
              性别
            </template>
            {{userInfo.gender}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-s-custom"></i>
              身份
            </template>
            <el-tag v-if="userInfo.status===0" type="">管理员</el-tag>
            <el-tag v-else type="success">普通用户</el-tag>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-coordinate"></i>
              操作
            </template>
            <el-button type="primary" icon="el-icon-edit" @click="getAccountInfo(userInfo.account)" ></el-button>
            <el-button type="danger" icon="el-icon-delete" @click="Visible[0].centerDialogVisible = true" ></el-button>
          </el-descriptions-item>
        </el-descriptions>
      </el-dialog>
<!--      表格-->
      <table>
        <thead>
        <tr>
          <th>用户名</th>
          <th>账号</th>
          <th>性别</th>
          <th>联系方式</th>
          <th>身份</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="(item,index) in userList" :key="index" >
          <td>{{item.userName}}</td>
          <td>{{item.account}}</td>
          <td>{{item.gender}}</td>
          <td>{{item.phone}}</td>
          <td v-if="item.status===0 ">管理员</td>
          <td v-else>普通用户</td>
<!--          编辑操作-->
          <td>
            <el-button type="primary" icon="el-icon-edit" @click="getAccountInfo(item.account,1)" ></el-button>
            <el-button type="danger" icon="el-icon-delete" @click="getAccountInfo(item.account,2)" ></el-button>
<!--            删除提示-->
            <el-dialog
              title="删除用户"
              :visible.sync="Visible[0].centerDialogVisible"
              width="30%"
              center>
              <span>确定要删除此用户吗？</span>
              <span slot="footer" class="dialog-footer">
    <el-button @click="Visible[0].centerDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="deleteUser(item.account)">确 定</el-button>
  </span>
            </el-dialog>
<!--            修改用户信息-->
            <el-dialog title="修改信息" :visible.sync="Visible[0].dialogFormVisible">
              <el-form :model="Changeform">
                <el-form-item label="用户名" :label-width="formLabelWidth">
                  <el-input v-model="Changeform.name" autocomplete="off" ></el-input>
                </el-form-item>
                <el-form-item label="手机号" :label-width="formLabelWidth">
                  <el-input v-model="Changeform.phone" autocomplete="off" ></el-input>
                </el-form-item>
                <el-form-item label="密码" :label-width="formLabelWidth">
                  <el-input v-model="Changeform.password" autocomplete="off" ></el-input>
                </el-form-item>
                <el-form-item label="身份" :label-width="formLabelWidth">
                  <el-form-item>
                    <el-radio-group v-model="Changeform.status">
                      <el-radio label="0">管理员</el-radio>
                      <el-radio label="1">普通用户</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-form-item>
                <el-form-item label="性别" :label-width="formLabelWidth">
                  <el-form-item>
                    <el-radio-group v-model="Changeform.sex">
                      <el-radio label="男"></el-radio>
                      <el-radio label="女"></el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="Visible[0].dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="EditUser">确 定</el-button>
              </div>
            </el-dialog>
          </td>
        </tr>
        </tbody>
      </table>
<!--      分页-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total.user"
        background
      >
      </el-pagination>
    </el-card>

<!--    商品管理-->
    <el-card v-if="index===3">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input
            v-model="goodsName"
            placeholder="查找商品"
            clearable
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="SerachGoods"
            ></el-button>
          </el-input>
          <el-dialog title="商品信息" :visible.sync="Visible[1].dialogTableVisible">
            <el-descriptions class="margin-top" title="商品信息" :column="1" size="medium" border>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i>
                  商品名
                </template>
                {{ goodsInfo.goodsName }}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-paperclip"></i>
                  商品ID
                </template>
                {{ goodsInfo.goodsId }}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-money"></i>
                  商品价格
                </template>
                {{ goodsInfo.money }}￥
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-pie-chart"></i>
                  商品种类
                </template>
                {{goodsInfo.goodsClass}}
              </el-descriptions-item>
            </el-descriptions>
          </el-dialog>
        </el-col>
        <el-col :span="4">
          <el-button type="primary"  @click="Visible[1].dialogNewUserVisible=true">新增商品</el-button>
          <el-dialog title="新增商品" :visible.sync="Visible[1].dialogNewUserVisible">
            <el-form :model="goodsAddForm" ref="form" :rules="rules">
              <el-form-item label="商品名" :label-width="formLabelWidth">
                <el-input v-model="goodsAddForm.goodsName" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="商品类别" :label-width="formLabelWidth">
<!--                <el-input v-model="AddUserForm.phone" autocomplete="off"></el-input>-->
                <el-select v-model="goodsAddForm.goodsClass" clearable placeholder="请选择">
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="定价" :label-width="formLabelWidth">
                <el-input v-model="goodsAddForm.money" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="上传图片" :label-width="formLabelWidth">
                <el-input v-model="goodsAddForm.goodsPicture" autocomplete="off" placeholder="请上传图片的URL(非必填)"></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="Visible[1].dialogNewUserVisible = false">取 消</el-button>
              <el-button type="primary" @click="AddGoods">确 定</el-button>
            </div>
          </el-dialog>
        </el-col>
      </el-row>
      <!--      表格-->
      <table>
        <thead>
        <tr>
          <th>商品ID</th>
          <th>商品名</th>
          <th>商品类别</th>
          <th>价格</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="(item,index) in goodsList" :key="index">
          <td>{{item.goodsId}}</td>
          <td>{{item.goodsName}}</td>
          <td>{{item.goodsClass}}</td>
          <td>{{item.money}}￥</td>
          <!--          编辑操作-->
          <td>
            <el-button type="primary" icon="el-icon-edit" @click="getGoodsID(item.goodsId,1)" ></el-button>
            <el-button type="danger" icon="el-icon-delete" @click="getGoodsID(item.goodsId,2)" ></el-button>
            <!--            删除提示-->
            <el-dialog
              title="删除商品"
              :visible.sync="Visible[1].centerDialogVisible"
              width="30%"
              center>
              <span>确定要删除此商品吗？</span>
              <span slot="footer" class="dialog-footer">
    <el-button @click="Visible[1].centerDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="DeleteGoods">确 定</el-button>
  </span>
            </el-dialog>
            <!--            修改商品定价-->
            <el-dialog title="修改价格" :visible.sync="Visible[1].dialogFormVisible">
              <el-form :model="Changeform">
                <el-form-item label="商品价格" :label-width="formLabelWidth">
                  <el-input v-model="Changeform.goodsMoney" autocomplete="off"></el-input>
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="Visible[1].dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="ChangeGoods">确 定</el-button>
              </div>
            </el-dialog>
          </td>
            <!--            删除提示-->
            <el-dialog
              title="下架商品"
              :visible.sync="Visible[1].centerDialogVisible"
              width="30%"
              center>
              <span>确定要下架此商品吗？</span>
              <span slot="footer" class="dialog-footer">
    <el-button @click="Visible[1].centerDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="DeleteGoods">确 定</el-button>
  </span>
            </el-dialog>
        </tr>
        </tbody>
      </table>
      <!--      分页-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10, 20, 50]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total.goods"
        background
      >
      </el-pagination>
    </el-card>

<!--    外卖管理-->
    <el-card v-if="index===4">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input
            v-model="dishName"
            placeholder="查找外卖"
            clearable
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="SerachDish"
            ></el-button>
          </el-input>
          <el-dialog title="菜品信息" :visible.sync="Visible[2].dialogTableVisible">
            <el-descriptions class="margin-top" title="菜品信息" :column="1" size="medium" border>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i>
                  菜品名
                </template>
                {{ dishInfo.dishName }}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-paperclip"></i>
                  菜品ID
                </template>
                {{ dishInfo.dishId }}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-money"></i>
                  菜品价格
                </template>
                {{ dishInfo.money }}￥
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-pie-chart"></i>
                  菜品种类
                </template>
                {{dishInfo.dishClass}}
              </el-descriptions-item>
            </el-descriptions>
          </el-dialog>
        </el-col>
        <el-col :span="4">
          <el-button type="primary"  @click="Visible[2].dialogNewUserVisible=true">新增外卖</el-button>
          <el-dialog title="新增外卖" :visible.sync="Visible[2].dialogNewUserVisible">
            <el-form :model="dishAddForm" ref="form" :rules="rules">
              <el-form-item label="外卖名" :label-width="formLabelWidth">
                <el-input v-model="dishAddForm.dishName" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="菜品类别" :label-width="formLabelWidth">
                <!--                <el-input v-model="AddUserForm.phone" autocomplete="off"></el-input>-->
                <el-select v-model="dishAddForm.dishClass" clearable placeholder="请选择">
                  <el-option
                    v-for="item in options2"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="定价" :label-width="formLabelWidth">
                <el-input v-model="dishAddForm.money" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="上传图片" :label-width="formLabelWidth">
                <el-input v-model="dishAddForm.picture" autocomplete="off" placeholder="请上传图片的URL(非必填)"></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="Visible[2].dialogNewUserVisible = false">取 消</el-button>
              <el-button type="primary" @click="AddDish">确 定</el-button>
            </div>
          </el-dialog>
        </el-col>
      </el-row>
      <!--      表格-->
      <table>
        <thead>
        <tr>
          <th>菜品ID</th>
          <th>菜品名</th>
          <th>菜品类别</th>
          <th>价格</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="(item,index) in dishList" :key="index">
          <td>{{item.dishId}}</td>
          <td>{{item.dishName}}</td>
          <td>{{item.dishClass}}</td>
          <td>{{item.money}}￥</td>
          <td>
            <el-button type="primary" icon="el-icon-edit" @click="getDishID(item.dishId,1)" ></el-button>
            <el-button type="danger" icon="el-icon-delete" @click="getDishID(item.dishId,2)" ></el-button>
            <!--            修改商品定价-->
            <el-dialog title="修改价格" :visible.sync="Visible[2].dialogFormVisible">
              <el-form :model="Changeform">
                <el-form-item label="菜品价格" :label-width="formLabelWidth">
                  <el-input v-model="Changeform.dishMoney" autocomplete="off"></el-input>
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="Visible[2].dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="ChangeDish">确 定</el-button>
              </div>
            </el-dialog>
          </td>
          <!--            删除提示-->
          <el-dialog
            title="删除菜品"
            :visible.sync="Visible[2].centerDialogVisible"
            width="30%"
            center>
            <span>确定要删除此菜品吗？</span>
            <span slot="footer" class="dialog-footer">
    <el-button @click="Visible[2].centerDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="DeleteFoods">确 定</el-button>
  </span>
          </el-dialog>

        </tr>
        </tbody>
      </table>
      <!--      分页-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10, 20, 50]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total.dish"
        background
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import {DeleteUser, register,
  UserDividePage,UpdateUser,
  FindUserByAccount,AddGoodsInfo,
  GoodsDividePage,changeGoodsPrice,
  RemoveGoods,SelectGoodsByName,
  DishDividePage,AddDishInfo,
  SelectDishByName,changeDishPrice,
  RemoveFoods} from "@/api";

export default {
  props: ["index"],
  data() {
    const checkPhone = (rule, value, callback)=>{
        const phoneReg = /^1[3|4|5|7|8][0-9]{9}$/
        if (!value) {
          return callback(new Error('电话号码不能为空'))
        }
        setTimeout(() => {
          if (!Number.isInteger(+value)) {
            callback(new Error('请输入数字值'))
          } else {
            if (phoneReg.test(value)) {
              callback()
            } else {
              callback(new Error('电话号码格式不正确'))
            }
          }
        }, 100)
      }
    return {
      total:{
        user:0,
        goods:0,
        dish:0
      },
      Visible:[
        {
          centerDialogVisible: false,
          dialogFormVisible: false,
          dialogNewUserVisible:false,
          dialogTableVisible:false,
        },
        {
          centerDialogVisible: false,
          dialogFormVisible: false,
          dialogNewUserVisible:false,
          dialogTableVisible:false,
        },
        {
          centerDialogVisible: false,
          dialogFormVisible: false,
          dialogNewUserVisible:false,
          dialogTableVisible:false,
        }
      ],
      formLabelWidth: '120px',
      Key:{
        account:'',
        goodsId:'',
        dishId:''
      },
      goodsName:'',//搜索栏输入商品名
      FindItem:'',  //搜索栏输入账号
      dishName:'',//搜索栏输入外卖名
      userList:[],
      goodsList:[],
      dishList:[],
      Changeform: {
        name: '',
        phone: '',
        password: '',
        status: '',
        sex:'',
        goodsMoney:'',
        dishMoney:''
      }, //修改用户信息记录表
      queryInfo: {
        pagenum: 1,
        pagesize: 10
      },
      rules:{
        username:[
          {required:true,trigger:'blur',message:'请输入用户名'},
          { min: 3, max: 10, message: "长度在 3 到 10个字符", trigger: "blur" },
        ],
        password: [
          {required:true,trigger:'blur',message:'请输入密码'},
          { min: 3, max: 10, message: "长度在 3 到 10个字符", trigger: "blur" },
        ],
        phone: [
          {required:true,trigger:'blur',message:'请输入正确的手机号',validator: checkPhone}
        ],
        account:[{required:true,trigger:'blur',message:'请输入帐号'}],
        sex: [{required:true,trigger:'blur',message:'请选择性别'}]
      },
      userInfo:{},
      goodsInfo:{},
      dishInfo:{},
      options: [{
        value: '医药',
        label: '医药'
      }, {
        value: '办公',
        label: '办公'
      }, {
        value: '食品',
        label: '食品'
      }, {
        value: '生鲜',
        label: '生鲜'
      }, {
        value: '日化',
        label: '日化'
      }],
      options2: [{
        value: '炒菜盖饭',
        label: '炒菜盖饭'
      }, {
        value: '米粉面条',
        label: '米粉面条'
      }, {
        value: '汉堡披萨',
        label: '汉堡披萨'
      }, {
        value: '饮品甜点',
        label: '饮品甜点'
      }, {
        value: '炒饭拌饭',
        label: '炒饭拌饭'
      }],
      goodsAddForm:{
        goodsClass:'',
        goodsName:'',
        goodsPicture:'',
        money:''
      },
      AddUserForm:{
        username:"",
        password:"",
        phone:"",
        account:"",
        sex: ''
      },
      dishAddForm:{
        dishClass:'',
        dishName:'',
        picture:'',
        money:''
      },
    };
  },
  mounted() {
    // this.function()
     this.loadingInfo()

  },
  methods: {
    //工具函数
    Clean(num){
      switch (num){
        case 0:
          this.AddUserForm.username='',
          this.AddUserForm.account='',
          this.AddUserForm.password='',
          this.AddUserForm.sex='',
          this.AddUserForm.phone=''
          break;

        case 1:
          this.goodsAddForm.goodsClass='',
          this.goodsAddForm.goodsName='',
          this.goodsAddForm.goodsPicture='',
          this.goodsAddForm.money=''
          break;

        case 2:
          this.dishAddForm.dishClass='',
          this.dishAddForm.dishName='',
          this.dishAddForm.picture='',
          this.dishAddForm.money=''
          break;
      }
    },
    /***********分页功能***********/
    loadingInfo(){
      this.NewGoodsPage()
      this.NewPage()
      this.NewDishPage()
    },
    handleSizeChange(newSize){
      this.queryInfo.pagesize = newSize
      this.loadingInfo()
    },
    handleCurrentChange(newPage){
      this.queryInfo.pagenum = newPage
      this.loadingInfo()
    },

    /******************用户管理**************/
    //获取账号字段信息
    getAccountInfo(account,num){
      if(num===2){
        this.Visible[0].centerDialogVisible = true
      }else if(num === 1){
        this.Visible[0].dialogFormVisible = true
      }
      this.Key.account = account
    },
    // 分页请求用户数据
    async NewPage(){
      UserDividePage({
        "pageNum":this.queryInfo.pagenum,
        "pageSize":this.queryInfo.pagesize
      }).then(res =>{
        // this.userList=res.data
        this.total.user=res.data.dataSum
        this.userList=res.data.data
      })
    },
    //添加用户
    AddUsers(){
      this.Visible[0].dialogNewUserVisible=true
      this.$refs.form.validate((isPass)=> {
        if (isPass) {
          register({
            "userName": this.AddUserForm.username,
            "account": this.AddUserForm.account,
            "pswd": this.AddUserForm.password,
            "gender": this.AddUserForm.sex,
            "phone": this.AddUserForm.phone,
            "status":1
          }).then(res => {
            if (res.status === 200) {
              this.$message({
                message: '注册成功',
                type: 'success'
              })
              this.NewPage()
            } else if (res.status === 201) {
              this.$message({
                message: '账号已被注册',
                type: 'warning'
              })
            } else {
              this.$message.error('注册失败')
            }
            this.Clean(0)
            this.Visible[0].dialogNewUserVisible=false
          })
        }
      })
    },
    // 删除用户
    deleteUser(){
      //发送请求
      DeleteUser({
        "account":this.Key.account
      }).then((res)=>{
        if(res.status===200){
          this.$message({
            message:'删除成功！',
            type:"success"
          })
          this.NewPage()
        }else{
          this.$message({
            message:'删除失败！',
            type:"warning"
          })
        }
      })
      this.Visible[0].centerDialogVisible = false
      this.Visible[0].dialogTableVisible = false

    },
    //修改用户信息
    EditUser(){
      // console.log(this.account)
      UpdateUser({
        "account":this.Key.account,
        "userName":this.Changeform.name,
        "phone":this.Changeform.phone ,
        "pswd":this.Changeform.password,
        "status":this.Changeform.status,
        "gender":this.Changeform.sex,
      }).then(res=>{
        if(res.status===200){
          this.$message.success("信息更新成功！")
          this.NewPage()
        }else {
          this.$message.error("信息更新失败！")
        }
      })
      this.Visible[0].dialogFormVisible = false
      this.Visible[0].dialogTableVisible = false
    },
    //查找用户
    FindUser(){
      FindUserByAccount(this.FindItem).then(res=>{
        if(this.FindItem===''){
          this.$message.warning('请输入账号以查询！')
        }
        else{
          if(res.data.length!==0){
            this.userInfo=res.data[0]
            this.Visible[0].dialogTableVisible = true
            // console.log(res.data)
          }else{
            this.$message.error('查无此用户！')
          }
        }
      })
    },

    /***************商品管理***************/
    //获取商品ID字段信息
    getGoodsID(ID,num){
      if(num===2){
        this.Visible[1].centerDialogVisible = true
      }else if(num === 1){
        this.Visible[1].dialogFormVisible = true
      }
      this.Key.goodsId = ID
    },
    //添加商品
    AddGoods(){
      AddGoodsInfo({
        "goodsClass": this.goodsAddForm.goodsClass,
        "goodsName": this.goodsAddForm.goodsName,
        "goodsPicture": this.goodsAddForm.goodsPicture,
        "money":this.goodsAddForm.money
      }).then(res=>{
        if (res.status === 200) {
          this.$message({
            message: '新增成功',
            type: 'success'
          })
          this.NewGoodsPage()
        } else {
          this.$message.error('新增失败')
        }
        this.Visible[1].dialogNewUserVisible=false
        this.Clean(1)
      })
    },
    //修改商品定价
    ChangeGoods(){
      changeGoodsPrice({
        "goodsId":this.Key.goodsId,
        "money":this.Changeform.goodsMoney
      }).then(res=>{
        if(res.status===200){
          this.$message.success("价格更新成功！")
          this.NewGoodsPage()
        }else {
          this.$message.error("价格更新失败！")
        }
      })
      this.Visible[1].dialogFormVisible = false
      this.Visible[1].dialogTableVisible = false
    },
    // 分页请求商品数据
    async NewGoodsPage(){
      GoodsDividePage({
        "pageNum":this.queryInfo.pagenum,
        "pageSize":this.queryInfo.pagesize
      }).then(res=>{
        this.total.goods=res.data.dataSum
        this.goodsList=res.data.data
      })
    },
    //删除商品信息
    DeleteGoods(){
      RemoveGoods({
        "goodsId":this.Key.goodsId
      }).then(res =>{
        if(res.data){
          this.$message({
            message:'删除成功！',
            type:"success"
          })
          this.NewGoodsPage()
        }else{
          this.$message({
            message:'删除失败！',
            type:"warning"
          })
        }
      })
      this.Visible[1].centerDialogVisible = false
      this.Visible[1].dialogTableVisible = false
    },
    //查找商品信息
    SerachGoods(){
      SelectGoodsByName({
        "goodsName":this.goodsName
      }).then(res=>{
        if(this.goodsName===''){
          this.$message.warning('请输入商品名以查询！')
        }
        else{
          if(res.data.length!==0){
            this.goodsInfo=res.data[0]
            this.Visible[1].dialogTableVisible = true
            // console.log(res.data)
          }else{
            this.$message.error('没有此商品！')
          }
        }
      })
    },

    /***************外卖管理***************/
    //获取商品ID字段信息
    getDishID(ID,num){
      if(num===2){
        this.Visible[2].centerDialogVisible = true
      }else if(num === 1){
        this.Visible[2].dialogFormVisible = true
      }
      this.Key.dishId = ID
    },
    // 分页请求外卖数据
    async NewDishPage(){
      DishDividePage({
        "pageNum":this.queryInfo.pagenum,
        "pageSize":this.queryInfo.pagesize
      }).then(res=>{
        this.total.dish=res.data.dataSum
        this.dishList=res.data.data
      })
    },
    // 添加菜品
    AddDish(){
      AddDishInfo({
        "dishClass":this.dishAddForm.dishClass,
        "dishName":this.dishAddForm.dishName,
        "picture":this.dishAddForm.picture,
        "money":this.dishAddForm.money
      }).then(res=>{
        if (res.status === 200) {
          this.$message({
            message: '新增成功',
            type: 'success'
          })
          this.NewDishPage()
        } else {
          this.$message.error('新增失败')
        }
        this.Clean(2)
        this.Visible[2].dialogNewUserVisible=false
      })
    },
    //查找外卖信息
    SerachDish(){
      SelectDishByName({
        "dishName":this.dishName
      }).then(res=>{
        if(this.dishName===''){
          this.$message.warning('请输入菜品名以查询！')
        }
        else{
          if(res.data.length!==0){
            this.dishInfo=res.data[0]
            this.Visible[2].dialogTableVisible = true
            // console.log(res.data)
          }else{
            this.$message.error('没有此类菜品！')
          }
        }
      })
    },
    //修改外卖定价
    ChangeDish(){
      changeDishPrice({
        "dishId":this.Key.dishId,
        "money":this.Changeform.dishMoney
      }).then(res=>{
        if(res.status===200){
          this.$message.success("价格更新成功！")
          this.NewDishPage()
        }else {
          this.$message.error("价格更新失败！")
        }
      })
      this.Visible[2].dialogFormVisible = false
      this.Visible[2].dialogTableVisible = false
    },
    //删除外卖
    DeleteFoods(){
      RemoveFoods({
        "dishId":this.Key.dishId
      }).then(res =>{
        if(res.data){
          this.$message({
            message:'删除成功！',
            type:"success"
          })
          this.NewDishPage()
        }else{
          this.$message({
            message:'删除失败！',
            type:"warning"
          })
        }
      })
      this.Visible[2].centerDialogVisible = false
      this.Visible[2].dialogTableVisible = false
    }
  },

};
</script>

<style scoped>
table {
  border-collapse: collapse;
  width: 100%;
  margin-top: 10px;
  margin-bottom: 10px;
}
th, td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid #ddd;
}
th {
  background-color: #409EFF;
  color: white;
}
tr:nth-child(even) {
  background-color: #f2f2f2;
}
</style>
